package com.fanbai.score.business.http;

import android.content.Context;

import com.fanbai.score.business.beans.OrderInfo_Bean;
import com.fanbai.score.common.Utils.JsonUtils;
import com.fanbai.score.common.http.CallBack;
import com.fanbai.score.common.http.HttpUtils;
import com.fanbai.score.common.http.WebCodes;
import com.tencent.bugly.crashreport.CrashReport;

import java.util.HashMap;
import java.util.List;

/**
 * Created by acer on 2017/6/18.
 */

public class Busin_Order_RequestNet {


    /**
     * 获取订单详情
     * @param ctx
     * @param callBack
     */
    public static void getorderinfobyoid(final Context ctx, String oid
                                         ,final CallBack<OrderInfo_Bean> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getorderinfobyoid");
        params.put("oid", oid);
        String url = WebCodes.HTTP_URL_BUSIN_ORDER ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    OrderInfo_Bean bean = JsonUtils.toBean(body, OrderInfo_Bean.class);
                        callBack.onSuccess(ret, msg, bean);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     *获取店员的订单信息
     * @param ctx
     * @param callBack
     */
    public static void getorderinfosbysmuid(final Context ctx, String smuid, final CallBack<List<OrderInfo_Bean>> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getorderinfosbysmuid");
        params.put("smuid", smuid);
        String url = WebCodes.HTTP_URL_BUSIN_ORDER ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    List<OrderInfo_Bean> beans = JsonUtils.toArr(body, OrderInfo_Bean[].class);
                    callBack.onSuccess(ret, msg, beans);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 订单提醒
     * @param ctx
     * @param callBack
     */
    public static void remindorder(final Context ctx, String oid, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "remindorder");
        params.put("oid", oid);
        String url = WebCodes.HTTP_URL_BUSIN_ORDER ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }

    /**
     * 获取店员今日订单统计
     * @param ctx
     * @param smuid
     * @param callBack
     */
    public static void getorderstatfortoday(final Context ctx, String smuid, final CallBack<String> callBack) {
        HashMap<String, String> params = new HashMap<String, String>();
        params.put("type", "getorderstatfortoday");
        params.put("smuid", smuid);
        String url = WebCodes.HTTP_URL_BUSIN_ORDER ;
        HttpUtils.post(ctx, url, params, new HttpUtils.BeanCallBack() {
            @Override
            public void onSuccess(String ret, String msg, String body) {
                try {
                    callBack.onSuccess(ret, msg, body);
                } catch (Exception e) {
                    e.printStackTrace();
                    if (callBack != null)
                        callBack.onFailure(ret, "未知类型异常", null);
                    CrashReport.postCatchedException(e);
                }
            }

            @Override
            public void onFailure(String ret, String msg, String body) {
                if (callBack != null) {
                    callBack.onFailure(ret, msg, body);
                }
            }

            @Override
            public void onError(String code, Exception e) {
                if (callBack != null)
                    callBack.onError(code, e.getMessage());
            }
        });
    }


}
